<!DOCTYPE html>
<html lang="en">
<head>
    <title>选择就诊人</title>
    <titleType style="display: none">selectePerson</titleType>
    <%- include('../../../_global/baseLibs') %>
    <script type="text/javascript" src="/static/lib/util.js"></script>
</head>
<body>
<section class="page-wrap page-family">
    <!-- header start -->
    <header id="header" class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" onclick="jump('/html/adapter/yygn/yyInfo.html','预约信息')"><i
                        class="iconfont icon-back"></i></a>
            </div>
            <div class="title">选择就诊人</div>
        </div>
    </header>
    <!-- header end -->
    <!--content start-->
    <section class="content">
        <aside class="family-list-box">
            <ul class="default-list" id="family_list">

            </ul>
        </aside>
    </section>
    <!--content end-->
</section>
<script type="text/javascript">

    var referer = document.referrer;

    var relations = {
        '0': '本人',
        '1': '父母',
        '2': '子女',
        '3': '亲属',
        '4': '朋友',
        '9': '其他',
        "5": '配偶'
    };
    var getSetected = function (data) {
        data = data.split(",");
        var fromUrl = $.QuickUrlUtils.getRequest("from");
        if (fromUrl == "hospitalRecords") {
            fromUrl = "hospitalRecords/hospitalRecords"
        }
        if(StringUtils.isEmpty(fromUrl)){
            fromUrl = referer;
        }
        $.QuickUrlUtils.redirectJSBridge({
            url: fromUrl + "?id=" + data[0] + "&name=" + data[1]
            , animate: "pop"
            ,refreshUrl: fromUrl
        });
    }

    var page_selectePerson = (function($, page_selectePerson) {

        function getFamilyList() {

            var ZXFW_ZXXQ = StoreCache.getCache("jkcsUserInfo");
            var userId = ZXFW_ZXXQ.USERID;
            var parmas = {
                USERID: userId,
            };

            $.QuickRemote.AjaxJson({
                funcName: "/api/jkcs-grzx/jrlb/queryList"
                ,params: parmas
                ,callback: familyList
            });
            function familyList(request) {
                var list = request;
                var mylist = JSON.stringify(list);
//            sessionStorage.familyinfo=JSON.stringify(list);
                StoreCache.setCache("familyinfo", mylist);
//            if (result.state == "true") {
                if (list.length > 0) {
                    var Str = "";
//                    var list = result.rows;
//                    var listId=result.rows.ID;
                    //var kinships = ["本人","父母","子女","亲属","朋友","其他"];
                    //判断来源
                    for (var i = 0; i < list.length; i++) {
                        var jumstr = '<li familyID=' + list[i].ID + ' TXID=' + list[i].TXID + '><a onclick="getSetected(\'' + list[i].ID + ',' + list[i].XM + '\')">';
//                            if (checkNotNull(reqs[0])) {
//                                jumstr = '<li><a onclick="jump(\'' + reqs[0]  + '\',\'' + reqs[1] + '\')">';
//                            }
                        Str += jumstr + '<div class="item-inner"><div class="item-media"><div class="img-wrap">'
                            + '<img class="img-wrap" />' + '</div></div>'
                            + '<div class="item-content text-wrap"><h4>'
                            + '<span class="name">' + list[i].XM + '</span>'
                            + '<span class="relation">' + relations[list[i].GX]
                            + '</span></h4><p>'
                            + '<span class="phone">手机号：' + list[i].SJ + '</span>';
                        if (list[i].MRJZR == '1') {
                            Str += '<span class="default-text">默认就诊人</span>'
                        }
                        Str += '</p></div></div></a></li>';

                    }
                    $('#family_list').append(Str);

                    $("#family_list li").each(function (i, item) {
                        var TXID = $(this).attr("txid");
                        $.QuickRemote.AjaxJson({
                            funcName: "/api/jkcs-grzx/jrlb/queryJrtxImage"
                            ,params: {TXID: TXID}
                            ,callback: txList
                            ,additionParams:item
                        });

                    })
                    function txList(data, item) {
                        var headsrc = data.info.jrtxFileData;
                        $(item).find(".img-wrap").attr("src", headsrc);

                    }
                } else {
                    $.QuickAlert.alertConfirm({
                        content: "未查到用户信息！", btn: ["确定"]
                    });
                }


                $("#family_list").on("click", "li", function () {
                    var id = $(this).attr("familyID");
                    var TXID = $(this).attr("txid");
                    StoreCache.setCache("TXID", TXID);
                    StoreCache.setCache("familyID", id);
                })


            }
        }
        var cfg_def = {
            getFamilyList: getFamilyList,
        }

        page_selectePerson.init = function(cfg){
            $.extend(page_selectePerson, cfg_def, cfg);
            var u = navigator.userAgent.toLowerCase();
            if (u.indexOf('micromessenger') != -1) {
                $("#titleBtn").show();
            }

            page_selectePerson.getFamilyList();

        }

        return page_selectePerson;
    })(jQuery, {});
</script>
</body>
</html>